package com.kikyou.service.impl;

import com.kikyou.pojo.BloodType;
import com.kikyou.mapper.BloodTypeMapper;
import com.kikyou.service.IBloodTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yuankaiqiang
 * @since 2022-03-07
 */
@Service
public class BloodTypeServiceImpl extends ServiceImpl<BloodTypeMapper, BloodType> implements IBloodTypeService {

    @Autowired(required = false)
    BloodTypeMapper bloodTypeMapper;

    @Autowired
    private RedisTemplate redisTemplate;
    /**
     * @author     ：ltm
     * @date       ：2022/3/7
     * @time       : 10:40 PM
     * @description：查询所有的血型
     * @Param:
     * @return:
     */
    @Override
    public List<BloodType> findAllBloodType() {
        ListOperations listOperations = redisTemplate.opsForList();
        List<BloodType> bloods = listOperations.range("blood", 0, -1);
        if (CollectionUtils.isEmpty(bloods)){
            bloods=bloodTypeMapper.findAllBloodType();
            listOperations.rightPushAll("blood",bloods);
        }
        return bloods;
    }
}
